package com.net.rip.entity;

import java.io.*;
import java.util.List;
import java.util.Map;

/**
 * 路由器实体类
 */
public class Router implements Serializable {

    private String routerName;    //路由器名称
    private Map<String, Information> information;//路由器中路由表信息
    private List<Router> nearRouter;    //相邻路由器


    public Router() {
    }


    public Router(String routerName, Map<String, Information> information) {
        this.routerName = routerName;
        this.information = information;
    }

    public String getRouterName() {
        return routerName;
    }

    public Map<String, Information> getInformation() {
        return information;
    }

    public void setRouterName(String routerName) {
        this.routerName = routerName;
    }

    public void setInformation(Map<String, Information> information) {
        this.information = information;
    }

    public void setNearRouter(List<Router> nearRouter) {
        this.nearRouter = nearRouter;
    }

    public List<Router> getNearRouter() {
        return nearRouter;
    }

    @Override
    public String toString() {

        return "routerName:    " + routerName +
                "\ninformation:\n" +
                "目标网络  距离  下一跳" +
                information.values() +
                "\n";

    }

    // 深拷贝
    public Router myclone() {
        Router router = null;
        try {
            // 写入字节流
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(baos);
            oos.writeObject(this);

            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
            ObjectInputStream ois = new ObjectInputStream(bais);
            router = (Router) ois.readObject();
        } catch (IOException | ClassNotFoundException e) {
            e.printStackTrace();
        }
        return router;
    }
}


